package com.example.news.controller;


import annotation.RequireRoles;
import com.example.news.service.NewsinfoServiceImpl;
import entity.PageParam;
import entity.Rsp;
import entity.Newsinfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.List;

/**
 * 模块接口
 */

@RestController
@Api(value = " 模块接口",description=" 模块接口")
public class NewsinfoController {

    private static final Logger log = LoggerFactory.getLogger(NewsinfoController.class);

    @Autowired
    NewsinfoServiceImpl newsinfoService;



    @PostMapping("/searchSomeNewsinfoByPage")
    @RequireRoles(roles = {"admin","super_admin","news_admin","news_editor"},index = 2)
    @ApiOperation("查询所有 支持 多条件 分页 排序 查询")
    public Rsp searchSomeByPage(@RequestBody PageParam<Newsinfo> newsinfoPageParam,
                                @RequestHeader(value = "userId") String userId, @RequestHeader(value = "roleSign") String roleSign){

        log.info("userId:{}",userId);
        log.info("roleId:{}",roleSign);

        return Rsp.success(newsinfoService.searchSomeByPage(newsinfoPageParam));
    }


    @RequireRoles(roles = {"super_admin","admin","news_admin","news_editor"},index = 2)
    @PostMapping("/addOneNewsinfo")
    @ApiOperation("添加单个")
    public Rsp addOne(@RequestBody @Valid Newsinfo newsinfo, @RequestHeader(value = "userId") String userId, @RequestHeader(value = "roleSign") String roleSign){

        newsinfo.setCreateUserId(userId);
        return newsinfoService.addOne(newsinfo);
    }


    @RequireRoles(roles = {"super_admin","news_admin"},index = 2)
    @PostMapping("/deleteOneNewsinfoTrue")
    @ApiOperation("通过ID物理删除")
    public Rsp deleteOneNewsinfoTrue(@RequestBody Newsinfo newsinfo, @RequestHeader(value = "userId") String userId, @RequestHeader(value = "roleSign") String roleSign){

        return newsinfoService.deleteOneTrue(newsinfo.getId());
    }

    @RequireRoles(roles = {"super_admin","admin","news_admin","news_editor"},index = 2)
    @PostMapping("/updateNewsinfo")
    @ApiOperation("动态修改")
    public Rsp updateNewsinfo(@RequestBody Newsinfo newsinfo, @RequestHeader(value = "userId") String userId, @RequestHeader(value = "roleSign") String roleSign){


		newsinfo.setUpdateUserId(userId);
        return newsinfoService.update(newsinfo);
    }

    @RequireRoles(roles = {"super_admin","news_admin","news_editor"},index = 2)
    @PostMapping("/deleteNewsinfoLogical")
    @ApiOperation("通过ID逻辑删除")
    public Rsp deleteNewsinfoLogical(@RequestBody Newsinfo newsinfo, @RequestHeader(value = "userId") String userId, @RequestHeader(value = "roleSign") String roleSign){



        return newsinfoService.deleteLogical(newsinfo);
    }

    @RequireRoles(roles = {"super_admin","news_admin","news_editor"},index = 2)
    @PostMapping("/recoverNewsinfoLogical")
    @ApiOperation("逻辑恢复")
    public Rsp recoverNewsinfoLogical(@RequestBody Newsinfo newsinfo, @RequestHeader(value = "userId") String userId, @RequestHeader(value = "roleSign") String roleSign){



        return newsinfoService.recoverLogical(newsinfo);
    }


    @RequireRoles(roles = {"super_admin","news_admin"},index = 2)
    @PostMapping("/deleteBatchNewsinfoTrue")
    @ApiOperation("批量物理删除")
    public Rsp deleteBatchNewsinfoTrue(@RequestBody List<String> ids, @RequestHeader(value = "userId") String userId, @RequestHeader(value = "roleSign") String roleSign){



        return newsinfoService.deleteBatchTrue(ids);
    }

    @RequireRoles(roles = {"super_admin","news_admin","news_editor"},index = 2)
    @PostMapping("/deleteBatchNewsinfoLogical")
    @ApiOperation("批量逻辑删除")
    public Rsp deleteBatchNewsinfoLogical(@RequestBody List<String> ids, @RequestHeader(value = "userId") String userId, @RequestHeader(value = "roleSign") String roleSign){



        return newsinfoService.deleteBatchLogical(ids);
    }

    @RequireRoles(roles = {"super_admin","news_admin","news_editor"},index = 2)
    @PostMapping("/deleteSomeNewsinfoLogicalByCondition")
    @ApiOperation("条件逻辑删除")
    public Rsp deleteSomeNewsinfoLogicalByCondition(@RequestBody Newsinfo newsinfo, @RequestHeader(value = "userId") String userId, @RequestHeader(value = "roleSign") String roleSign){



        return newsinfoService.deleteSomeLogicalByCondition(newsinfo);
    }

    @RequireRoles(roles = {"super_admin","news_admin" },index = 2)
    @PostMapping("/deleteSomeNewsinfoTrueByCondition")
    @ApiOperation("条件物理删除")
    public Rsp deleteSomeNewsinfoTrueByCondition(@RequestBody Newsinfo newsinfo, @RequestHeader(value = "userId") String userId, @RequestHeader(value = "roleSign") String roleSign){



        return newsinfoService.deleteSomeTrueByCondition(newsinfo);
    }


    @RequireRoles(roles = {"super_admin","news_admin" ,"news_editor"},index = 2)
    @PostMapping("/getNewsinfoById")
    @ApiOperation("通过id获取新闻")
    public Rsp getNewsinfoById(@RequestBody Newsinfo newsinfo, @RequestHeader(value = "userId") String userId, @RequestHeader(value = "roleSign") String roleSign){



        return Rsp.success(newsinfoService.getOneById(newsinfo.getId()));
    }

}
